home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / utils / shell / cdialog-.9a / cdialog- / cdialog-0.9a / msgbox.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-15  |  2.7 KB  |  98 lines

  1. /*
  2.  *  msgbox.c -- implements the message box and info box
  3.  *
  4.  *  AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
  5.  *
  6.  *  This program is free software; you can redistribute it and/or
  7.  *  modify it under the terms of the GNU General Public License
  8.  *  as published by the Free Software Foundation; either version 2
  9.  *  of the License, or (at your option) any later version.
  10.  *
  11.  *  This program is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *  GNU General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU General Public License
  17.  *  along with this program; if not, write to the Free Software
  18.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #include "dialog.h"
  22.  
  23. /*
  24.  * Display a message box. Program will pause and display an "OK" button
  25.  * if the parameter 'pause' is non-zero.
  26.  */
  27. int
  28. dialog_msgbox (const char *title, const char *cprompt, int height, int width,
  29.         int pause)
  30. {
  31.     int i, x, y, key = 0;
  32.     WINDOW *dialog;
  33.     char *prompt=strclone(cprompt);
  34.  
  35.     tab_correct_str(prompt);
  36.     prompt=auto_size(prompt, &height, &width, (pause == 1 ? 2 : 0), (pause == 1 ? 12 : 0));
  37.     print_size(height, width);
  38.     ctl_size(height, width);
  39.  
  40.     if (begin_set == 1) {
  41.     x = begin_x;
  42.     y = begin_y;
  43.     } else {
  44.     /* center dialog box on screen */
  45.     x = (SCOLS - width) / 2;
  46.     y = (SLINES - height) / 2;
  47.     }
  48.  
  49. #ifdef HAVE_NCURSES
  50.     if (use_shadow)
  51.     draw_shadow (stdscr, y, x, height, width);
  52. #endif
  53.     dialog = newwin (height, width, y, x);
  54.     mouse_setbase (x, y);
  55.     keypad (dialog, TRUE);
  56.  
  57.     draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr);
  58.  
  59.     if (title != NULL) {
  60.     wattrset (dialog, title_attr);
  61.     wmove (dialog, 0, (width - strlen (title)) / 2 - 1);
  62.     waddch (dialog, ' ');
  63.     waddstr (dialog, title);
  64.     waddch (dialog, ' ');
  65.     }
  66.     wattrset (dialog, dialog_attr);
  67.     print_autowrap (dialog, prompt, width, 1, 2);
  68.  
  69.     if (pause) {
  70.     wattrset (dialog, border_attr);
  71.     wmove (dialog, height - 3, 0);
  72.     waddch (dialog, ACS_LTEE);
  73.     for (i = 0; i < width - 2; i++)
  74.         waddch (dialog, ACS_HLINE);
  75.     wattrset (dialog, dialog_attr);
  76.     waddch (dialog, ACS_RTEE);
  77.     wmove (dialog, height - 2, 1);
  78.     for (i = 0; i < width - 2; i++)
  79.         waddch (dialog, ' ');
  80.  
  81.     mouse_mkbutton (height - 2, width / 2 - 4, 6, '\n');
  82.     print_button (dialog, "  OK  ",
  83.               height - 2, width / 2 - 4, TRUE);
  84.  
  85.     wrefresh_lock(dialog);
  86.  
  87.         wtimeout(dialog, WTIMEOUT_VAL);
  88.     while (key != ESC && key != '\n' && key != ' ')
  89.             key=mouse_wgetch(dialog);
  90.     } else {
  91.     key = '\n';
  92.     wrefresh_lock(dialog);
  93.     }
  94.  
  95.     delwin (dialog);
  96.     return key == ESC ? -1 : 0;
  97. }
  98.